package ru.gerunn.test.thread;

public class MyQueueDumper<T> implements Runnable {

	private MyQueue<T> queue;

	public MyQueueDumper(MyQueue<T> queue) {
		this.queue = queue;
	}

	private long counter = 0;
	private long waited = 0;

	public void run() {
		while (true) {
			T t;
			try {
				counter++;
				System.out.println("counter: " + counter + "; waited " + waited + " milliseconds");
				while ((t = queue.get()) != null) {
					System.out.println(t);
				}
				try {
					waited = (long) Math.floor(Math.random() * 10000);
					Thread.sleep(waited);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}
